home *** CD-ROM | disk | FTP | other *** search
/ PsL Monthly 1993 December / PSL Monthly Shareware CD-ROM (December 1993).iso / prgmming / dos / c / dblmon.exe / DUALMON.C < prev    next >
C/C++ Source or Header  |  1992-06-15  |  5KB  |  156 lines

  1.  
  2. /*
  3.  * DUALMON.C - Nice little routine to allow output to a monochrome monitor
  4.  * setup as a secondary monitor.
  5.  *
  6.  * DUALMON.C was surgically extracted from BUGOUT (without pain killers) by:
  7.  *
  8.  *   Mark R. Holbrook
  9.  *   805-964-4471
  10.  *   76436,1224 Compuserve
  11.  *   76436.1224@compuserve.com
  12.  *
  13.  * You may use and distribute this program freely.  In fact, you can even
  14.  * modify this program at any time if you have an editor.  Hell for all that
  15.  * matters, you can even compile this program if you have a compiler.  If we
  16.  * are going to go this far, you can even delete it or convert it to COBOL!
  17.  * All I ask is that my name be kept with it and if you
  18.  * make any neat changes to it.  Please update the version number and
  19.  * send a copy back to me!
  20.  *
  21.  * If you really insist on sending me money for this.. this.. thing, well
  22.  * I guess I could make an exception...  Let's discuss it!
  23.  *
  24.  * Revision history:   (sadly typical)
  25.  * -----------------
  26.  *
  27.  * 0.40 First compile and run.  Compile went ok. The run is a totally
  28.  *      different story!
  29.  *
  30.  */
  31.  
  32. #define DUALVERSION  0.50
  33.  
  34. /*
  35.  * Include our own include file.  Define us as the main routine
  36.  */
  37. #define     DUALMAIN
  38. #include    <dualmon.h>
  39.  
  40. /*
  41.  * Other include files we need
  42.  */
  43. #include    <ctype.h>
  44. #include    <mem.h>
  45. #include    <stdarg.h>
  46. #include    <stdlib.h>
  47.  
  48. /*
  49.  * ScrollMono() - Scroll the entire contents of the monochrome
  50.  * display up 1 line.  (or at times directly into the core memory
  51.  * of the Naval Observatory Atomic clock computer thereby completely
  52.  * changing time and history as we know it.)
  53.  *
  54.  * What if you don't have a monochrome adapter?  Well on some machines
  55.  * this code is still harmless because whatever garbage exists at the
  56.  * address of the monochome adapter is moved around a bit and composted
  57.  * providing a rich but smelly environment for small living things.  On other
  58.  * machines this address maps directly into the Hollywood Hills Sanitation
  59.  * department valve control center.  During initial testing we (quite
  60.  * accidentally) caused Madonna's toilet to backup and overflow while she
  61.  * was using it.  (The court date has been set but a jury has not been
  62.  * selected since finding a jury of our peers is quite difficult).
  63.  */
  64. void  ScrollMono( unsigned int Lines )
  65. {
  66.   /* Vars */
  67.   register  int   i;
  68.   register  int   j;
  69.  
  70.   /* Scroll up as many lines as they desire */
  71.   for( i = 0; i < Lines; i++ )
  72.     {
  73.     /* Move the existing screen contents up 1 line */
  74.     movedata( 0xb000, 80*2, 0xb000, 0, (24*80*2) );
  75.  
  76.     /* Blank fill the bottom line */
  77.     for( j = 0; j < 80; j++ )
  78.       *(Mono+(24*80)+j) = 0x0720;
  79.     }
  80. } /* ScrollMono() */
  81.  
  82.  
  83. /*
  84.  * ClearMono() - Clear the entire monochrome display.
  85.  * You can call it as often as you like to clean
  86.  * up the appearance of your debug output.
  87.  */
  88. void  ClearMono( void )
  89. {
  90.   _fmemset( (void far *)Mono, 0x0720, (80*25*2) );
  91. } /* ClearMono() */
  92.  
  93.  
  94. /*
  95.  * PrintToMono() - Output directly to the monochrome display.
  96.  * You can specify a row and col to print to or you can specify a
  97.  * row == 0 to get a bottom line write then scroll up effect.
  98.  * The function supports multiple arguments (like printf).
  99.  */
  100. void  PrintToMono( unsigned int   Row,
  101.                    unsigned int   Col,
  102.                    unsigned int   Att,
  103.                             char  *Fmt, ... )
  104. {
  105.   /* Vars */
  106.   register  int       i;
  107.             int       Len;
  108.             char      *Msg;
  109.             char      buf[256];
  110.             va_list   arg;
  111.  
  112.   /* Convert the arguments into the buffer */
  113.   va_start( arg, Fmt );
  114.   vsprintf( buf, Fmt, arg );
  115.     va_end( arg );
  116.  
  117.   /* Point to the buffer and get it's length */
  118.   Msg = buf;
  119.   Len = strlen( Msg );
  120.  
  121.   /* Set a default attribute */
  122.   if( Att == 0 )
  123.     Att = 0x07;
  124.  
  125.   /*
  126.    * If the row is 0 then we scroll the mono display
  127.    * up a line and print to the bottom of the display
  128.    */
  129.   if( Row == 0 )
  130.     {
  131.     /* Scroll up one */
  132.     ScrollMono( 1 );
  133.  
  134.     /* Print to the bottom line */
  135.     for( i = 0; i < Len && i < 80; i++ )
  136.       *(Mono+(24*80)+i) = (Att << 8) | *(Msg+i);
  137.     }
  138.   else
  139.     {
  140.     /*
  141.      * Make row & col zero based - this is stupid! Why didn't write the
  142.      * code so I wouldn't have to do this.  I hate making things zero based!
  143.      * It just seemed like having 0 scroll up a line was so logical... Well
  144.      * you can change it if you like!
  145.      */
  146.     Row -= 1;
  147.     if( Col )
  148.       Col -= 1;
  149.  
  150.     /* Print to the desired row & col */
  151.     for( i = 0; i < Len && i < 80; i++ )
  152.       *(Mono+(Row*80)+Col+i) = (Att << 8) | *(Msg+i);
  153.     }
  154. } /* PrintToMono() */
  155.  
  156.